﻿@using VideoSeller.Business.Data.Enums
@model AdminWithdrawViewModel
@using System.Globalization


@{
	ViewBag.Title = "Withdraw";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

<h2>Withdraw</h2>

<table>
	<tr>
		<th>Login</th>
		<th>Withdraw Type</th>
		<th>Withdraw Data</th>
		<th>Withdraw Amount</th>
		<th>Status</th>
		<th>Actions</th>
	</tr>
	@foreach (var item in Model.Items) {
		<tr>
			<td>@item.Finance.Client.Login</td>
			<td>@(item.WithdrawTypeEnum.HasValue ? item.WithdrawTypeEnum.ToString() : string.Empty)</td>
			<td>@item.WithdrawData</td>
			<td>@Html.GetCurrencyString(item.Finance != null ? item.Finance.Total : 0)</td>
			<td>@item.OperationEnum.ToString()</td>
			<td>
                @if (item.OperationEnum == FinanceOperation.WithdrawRequest)
                {
                    using (Html.BeginForm("ProcessWithdraw", "Admin", new { postingId = item.Id, loginFilter = Model.LoginFilter }, FormMethod.Post, new { style = "float: left;" }))
                    {
                    <input type="submit" value="Process" />
                    }
                    <input type="button" value="Cancel" onclick="@string.Format("openCancelWithdrawWindow('{0}', '{1}');", item.Id, Model.LoginFilter)" style="float: left;"/>
                    
                    @*
                    using (Html.BeginForm("PartialProcessWithdraw", "Admin", new { postingId = item.Id, loginFilter = Model.LoginFilter }, FormMethod.Post, new { style = "float: left;" }))
                    {
                    <input type="submit" value="PartialProcess" />
                    }                 
                    *@

                    <div>
                        <script src="~/Scripts/paypal-button.min.js?merchant=@item.WithdrawData"
                            data-env=""
                            data-button="buynow"
                            data-quantity="1"
                            data-name="Withdraw to user from Visell.tv"
                            data-amount ="@string.Format(CultureInfo.CreateSpecificCulture("en-US"),"{0:C2}", (item.Value*(decimal)0.95)/100)"
                            data-currency="USD"
                            data-custom=""
                            data-callback="@*http://visell.tv/paypal/ipn*@">
                        </script>
                    </div>
                 }
			</td>
		</tr>
	}
</table>
<br/><br/>
@Html.Partial("_LoginFilter", new LoginFilterViewModel { Action = "Withdraw", Controller = "Admin" })

<div id="cancel-withdraw" title="Cancel Withdraw">
	<form id="cancelWithdrawForm" method="post" action="@Url.Action("CancelWithdraw", "Admin")">
		<input id="PostingId" name="PostingId" type="hidden"/>
		<input id="LoginFilter" name="LoginFilter" type="hidden"/>
		Reason<br/><textarea id="Reason" name="Reason"></textarea>
	</form>
</div>